/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.d2g.openrealestate.persistence;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author d2g
 */
@Entity
@Table(name = "offer", catalog = "dd111", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Offer.findAll", query = "SELECT o FROM Offer o"),
    @NamedQuery(name = "Offer.findByIdOffer", query = "SELECT o FROM Offer o WHERE o.idOffer = :idOffer"),
    @NamedQuery(name = "Offer.findByAmount", query = "SELECT o FROM Offer o WHERE o.amount = :amount"),
    @NamedQuery(name = "Offer.findByOfferDate", query = "SELECT o FROM Offer o WHERE o.offerDate = :offerDate")})
public class Offer implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "id_offer", nullable = false)
    private Long idOffer;
    @Basic(optional = false)
    @NotNull
    @Column(name = "amount", nullable = false)
    private long amount;
    @Basic(optional = false)
    @NotNull
    @Column(name = "offer_date", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date offerDate;
    @OneToMany(mappedBy = "winningIdOffer")
    private Collection<Announce> announceCollection;
    @JoinColumn(name = "client_username", referencedColumnName = "username", nullable = false)
    @ManyToOne(optional = false)
    private Client clientUsername;
    @JoinColumn(name = "id_announce", referencedColumnName = "id_announce", nullable = false)
    @ManyToOne(optional = false)
    private Announce idAnnounce;

    public Offer() {
    }

    public Offer(Long idOffer) {
        this.idOffer = idOffer;
    }

    public Offer(Long idOffer, long amount, Date offerDate) {
        this.idOffer = idOffer;
        this.amount = amount;
        this.offerDate = offerDate;
    }

    public Long getIdOffer() {
        return idOffer;
    }

    public void setIdOffer(Long idOffer) {
        this.idOffer = idOffer;
    }

    public long getAmount() {
        return amount;
    }

    public void setAmount(long amount) {
        this.amount = amount;
    }

    public Date getOfferDate() {
        return offerDate;
    }

    public void setOfferDate(Date offerDate) {
        this.offerDate = offerDate;
    }

    @XmlTransient
    public Collection<Announce> getAnnounceCollection() {
        return announceCollection;
    }

    public void setAnnounceCollection(Collection<Announce> announceCollection) {
        this.announceCollection = announceCollection;
    }

    public Client getClientUsername() {
        return clientUsername;
    }

    public void setClientUsername(Client clientUsername) {
        this.clientUsername = clientUsername;
    }

    public Announce getIdAnnounce() {
        return idAnnounce;
    }

    public void setIdAnnounce(Announce idAnnounce) {
        this.idAnnounce = idAnnounce;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idOffer != null ? idOffer.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Offer)) {
            return false;
        }
        Offer other = (Offer) object;
        if ((this.idOffer == null && other.idOffer != null) || (this.idOffer != null && !this.idOffer.equals(other.idOffer))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.com.d2g.openrealestate.persistence.Offer[ idOffer=" + idOffer + " ]";
    }
    
}
